update platform 2

Documentation Version for Comments and Changes

You are invited to make any changes...add any comments.

Changes will `eventually` be merged into the offical documentation.

Leave any commnents here...

...

... back to index page OE documentation



printf(1, "Our platform number is: %d", {platform()}) </eucode>

The evaluation of platform occurs at 'runtime', you may even use a switch statement with it.

switch platform() do 
    case WINDOWS then 
       -- Windows code 
    case LINUX then 
       -- LINUX code 
    case FREEBSD,NETBSD then 
       -- BSD code 
       ... etc 
    case else 
       crash("Unsupported platform") 
end switch 

Another way is to use parse-time evaluation using ifdefs.

ifdef WINDOWS then 
  -- Windows code 
elsifdef LINUX then 
  -- LINUX code 
elsifdef FREEBSD or NETBSD then 
  -- BSD code 
elsedef 
    crash("Unsupported platform") 
end ifdef 

With parse-time evalution you get faster execution, for there is no conditional in the final code. You can put this deeply inside a loop without penalty. You can test for UNIX to see if the platform has Unix-like properties and thus will work on new Unix-like platforms without modification. You can even put statements that are top-level, such as constant and routine defintions. However, since the interpreter skips over the platforms you are not running on, syntax errors can hide in this construct and if you misspell an OS name you will not get warned.

ifdef UNIX then 
	public constant SLASH='/' 
	public constant SLASHES = "/" 
	public constant EOLSEP = "\n" 
	public constant PATHSEP = ':' 
	public constant NULLDEVICE = "/dev/null" 
	ifdef OSX then 
		public constant SHARED_LIB_EXT = "dylib" 
	elsedef 
		public constant SHARED_LIB_EXT = "so" 
	end ifdef 
         
	public constant FOO =  SLASH == PATHSEP -- this has a hidden syntax error 
	 
elsifdef WINDOWS then 
 
	public constant SLASH='\\' 
	public constant SLASHES = "\\/:" 
	public constant EOLSEP = "\r\n" 
	public constant PATHSEP = ';' 
	public constant NULLDEVICE = "NUL:" 
	public constant SHARED_LIB_EXT = "dll" 
	 
elsifdef TRASHOS then  -- this symbol is never defined -- no error here either 
        
end ifdef 
Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu